package com.sgb.capital.view.widget;

import android.content.Context;
import android.view.View;

import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.constant.RefreshState;

import androidx.annotation.NonNull;

/**
 * @author: 杨畔
 * @date: 2020/12/28 18:46
 * @Description: 刷新头部，smartRefresh用
 */
public class MyRefreshHeader extends ClassicsHeader {

    public MyRefreshHeader(Context context) {
        super(context);
        //隐藏更新事件字段
        setEnableLastTime(false);
        //修改文案
        mTextPulling = "下拉刷新";
    }

    @Override
    public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
        final View arrowView = mArrowView;
        final View updateView = mLastUpdateText;
        arrowView.setVisibility(GONE);
        switch (newState) {
            case None:
                updateView.setVisibility(mEnableLastTime ? VISIBLE : GONE);
            case PullDownToRefresh:
                mTitleText.setText(mTextPulling);
                break;
            case Refreshing:
            case RefreshReleased:
                mTitleText.setText(mTextRefreshing);
                break;
            case ReleaseToRefresh:
                mTitleText.setText(mTextRelease);
                break;
            case ReleaseToTwoLevel:
                mTitleText.setText(mTextSecondary);
                break;
            case Loading:
                arrowView.setVisibility(GONE);
                mTitleText.setText(mTextLoading);
                break;
        }
    }
}
